Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var leverStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showLeverParamType.do?type=LeverParam',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad: true
});

var solventStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=SolvencyParam',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad: true
});

var industryStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showIndustryParamType.do?type=IndustryParam',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad: true
});

var regionStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
	url:'showType.do?type=AreaParam',
	method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
	{name:'name'}, 
	{name:'code'}
	]) ,
	autoLoad: true
});


//债项详情
var addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
title:'限额计算',
renderTo:"form",
height: 240, 
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 120, 
items: 
[ 
{ xtype: 'fieldset', 
title:'限额参数', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[


{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
	        		id:'netAsset',
	        		name: 'netAsset', 
	        		fieldLabel: '有效净资产(元)', 
	        		readOnly:true,
	        		width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
	       		id:'obbalance',
	       		name: 'obbalance', 
	       		fieldLabel: '其他行的债务余额(元)', 
	       		readOnly:false,
	       		width: 200 
	}
	]} 
	]},

{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{

	 xtype: 'combo',
	 id : "pdfactor",
	 name: 'pdfactor',
     store :leverStore,
     fieldLabel: '客户评级杠杆系数',
     valueField : 'name',
     displayField : 'name',
     emptyText : '请选择客户评级杠杆系数...',
     editable: false,
     typeAhead : true,
     width: 200,
     mode:'remote',  
     triggerAction : 'all',
     selectOnFocus : true,
     hiddenName:'pdfactor'
	
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{

			//	 xtype: 'combo',
			//	 id : "solventFactor",
			//	 name: 'solventFactor',
			//     store :solventStore,
			//     fieldLabel: '偿债能力增长系数',
			//     valueField : 'name',
			//     displayField : 'name',
			//     emptyText : '请选择偿债能力增长系数...',
			//     editable: false,
			//     readyOnly: true,
			//     typeAhead : true,
			//     width: 200,
			//     mode:'remote',  
			//     triggerAction : 'all',
			//     selectOnFocus : true,
			//     hiddenName:'solventFactor'
        	   
        	   xtype: 'textfield', 
          		id:'solventFactor',
          		name: 'solventFactor', 
          		fieldLabel: '偿债能力增长系数', 
          		allowBlank: false,
          		readOnly:true,
          		width: 200
}
]} 
]},{
layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
	 xtype: 'combo',
	 id : "industryFactor",
	 name: 'industryFactor',
     store :industryStore,
     fieldLabel: '行业杠杆率',
     valueField : 'name',
     displayField : 'name',
     emptyText : '请选择行业杠杆率...',
     editable: false,
     typeAhead : true,
     width: 200,
     mode:'remote',  
     triggerAction : 'all',
     selectOnFocus : true,
     hiddenName:'industryFactor'
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   //当前暂时默认为1.0
				//	 xtype: 'combo',
				//	 id : "regionFactor",
				//	 name: 'regionFactor',
				//     store :regionStore,
				//     fieldLabel: '地区调整系数',
				//     valueField : 'name',
				//     displayField : 'name',
				//     emptyText : '请选择地区调整系数...',
				//     editable: false,
				//     readyOnly: true,
				//     typeAhead : true,
				//     width: 200,
				//     mode:'remote',  
				//     triggerAction : 'all',
				//     selectOnFocus : true,
				//     hiddenName:'regionFactor',
        	xtype: 'textfield', 
       		id:'regionFactor',
       		name: 'regionFactor', 
       		fieldLabel: '地区调整系数', 
       		allowBlank: false,
       		readOnly:true,
       		width: 200
     
}
]} 
]},

	{
		layout:"column",
		items:[
		{
			columnWidth : .5, // 该列有整行中所占百分比
		           layout : "form",
		           items : [{
		        	   xtype: 'textfield', 
		        		id:'outGuaranty',
		        		name: 'outGuaranty', 
		        		fieldLabel: '或有负债(元)', 
		        		emptyText: '必填', 
		        		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
		        	 	regexText:'只能输入整数或小数！' , 
		        		blankText: '对外担保不能为空', 
		        		allowBlank: false, 
		        		width: 200
		}
		]},
		{
			columnWidth : .5, // 该列有整行中所占百分比
		           layout : "form",
		           items : [{
		        	   xtype: 'textfield', 
		        		id:'debtBalance',
		        		name: 'debtBalance', 
		        		fieldLabel: '客户在本行的债务余额(元)', 
		        		emptyText: '必填', 
		        		regex:/^[0-9]+\.{0,1}[0-9]{0,2}$/,
		        	 	regexText:'只能输入整数或小数！' , 
		        		blankText: '债务余额不能为空', 
		        		allowBlank: false, 
		        		width: 200
		}
		]}
		]},
] 
}],
buttonAlign:'right',
buttons: 
[  

{ text: '计算', handler: editFunction },
] 
});

//结果表单
resultForm = new Ext.form.FormPanel({ 
id: 'resultForm', 
height: 140,
renderTo:"result",
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 120, 
items: 
[ { xtype: 'fieldset', 
title: '计算结果', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[ 
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'textfield', 
        		id:'initLimit',
        		name: 'initLimit', 
        		fieldLabel: '初始限额(元)', 
        		readOnly:true,
        		width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{

	xtype: 'textfield', 
	id:'pdLimit',
	name: 'pdLimit', 
	fieldLabel: '客户评级限额(元)', 
	readOnly:true,
	width: 200
}
]} 
]},
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{

	xtype: 'textfield', 
	id:'rLimit',
	name: 'rLimit', 
	fieldLabel: '监管限额(元)', 
	readOnly:true,
	width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{

	xtype: 'textfield', 
	id:'finalLimit',
	name: 'finalLimit', 
	fieldLabel: '客户最终限额(元)', 
	readOnly:true,
	width: 200
}
]} 
]}
] 
}]
,
buttonAlign:'right',
buttons: 
[  
{ text: '保存', handler:saveDebtRating },
{ text: '重新计算', handler:returnDebtRating }
],
});

//表单加载数据
addForm.form.load({  
    waitMsg : '正在加载数据请稍后',
    waitTitle : '提示',
    url : 'riskApp/getCustLimit.do', 
    method:'post',
    success:function(form,action){
    	Ext.getCmp("netAsset").setValue(action.result.data.netAsset);
    	Ext.getCmp("finalLimit").setValue(action.result.data.finalLimit);
		Ext.getCmp("initLimit").setValue(action.result.data.initLimit);
		Ext.getCmp("pdLimit").setValue(action.result.data.pdlimit);
		Ext.getCmp("rLimit").setValue(action.result.data.rlimit);
    },  
    failure:function(form,action){
		//window.location.href="view/obligation/DebtGuaranteeInfo.jsp";
    }  
});

function editFunction(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/calculateCustLimit.do', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("finalLimit").setValue(action.result.data.finalLimit);
	    		Ext.getCmp("initLimit").setValue(action.result.data.initLimit);
	    		Ext.getCmp("pdLimit").setValue(action.result.data.pdlimit);
	    		Ext.getCmp("rLimit").setValue(action.result.data.rlimit);
	    		Ext.getCmp("obbalance").setValue(action.result.data.obbalance);
				
				Ext.Msg.alert('提示', '计算成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '计算失败！'); 
				
			} 
		}); 
	}
}    


function returnDebtRating(){
	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/calculateCustLimit.do', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("finalLimit").setValue(action.result.data.finalLimit);
	    		Ext.getCmp("initLimit").setValue(action.result.data.initLimit);
	    		Ext.getCmp("pdLimit").setValue(action.result.data.pdlimit);
	    		Ext.getCmp("rLimit").setValue(action.result.data.rlimit);
	    		Ext.getCmp("obbalance").setValue(action.result.data.obbalance);
				
				Ext.Msg.alert('提示', '计算成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '计算失败！'); 
				
			} 
		}); 
	}
}

function saveDebtRating(){
	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/calculateCustLimit.do?isSave=1', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("finalLimit").setValue(action.result.data.finalLimit);
	    		Ext.getCmp("initLimit").setValue(action.result.data.initLimit);
	    		Ext.getCmp("pdLimit").setValue(action.result.data.pdlimit);
	    		Ext.getCmp("rLimit").setValue(action.result.data.rlimit);
	    		Ext.getCmp("obbalance").setValue(action.result.data.obbalance);
				
				Ext.Msg.alert('提示', '保存成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
				
			} 
		}); 
	}
}

}); 